package com.glory.brepda.activity.lanjian;


import android.text.format.DateUtils;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.glory.brepda.R;
import com.glory.brepda.activity.check.CheckDescActivity;
import com.glory.brepda.base.BaseActivity;
import com.glory.brepda.base.Constant;
import com.glory.brepda.entity.LotAndPackagingfileEntity;
import com.glory.brepda.entity.SheetInfoEntity;
import com.glory.brepda.entity.response.BaseResponseBean;
import com.glory.brepda.utils.NetUtils;
import com.glory.brepda.utils.ShowDialog;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.model.Response;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_DialogEntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_EntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_StaticMembers;
import com.pda.platform.ui.ui_pdaplatform.view.FreeUI_ClearEditText;

import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;

import butterknife.BindView;
import butterknife.OnClick;

public class WaferReceiveActivity extends BaseActivity {

    @BindView(R.id.tvBaseSubmit)
    TextView tvBaseSubmit;
    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.llMain)
    LinearLayout llMain;
    @BindView(R.id.btn)
    Button btn;
    @BindView(R.id.etWoID)
    FreeUI_ClearEditText etWoID;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_wafer_receive;
    }

    @Override
    protected void initView() {
        String title = getIntent().getStringExtra(FreeApi_StaticMembers.SHOW_PLUGIN_KEY);
        tvTitle.setText(title);
        tvBaseSubmit.setVisibility(View.GONE);
        setMainLayout(llMain);
    }

    @OnClick({R.id.btn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn:
//                showSubmitDialog(() -> {
                    if(getText(etWoID).equals("") || getText(etWoID)==null){
                        showToast("请扫描二维码领料!",false);
                        return;
                    }
                    FreeUI_EntityCallBack<BaseResponseBean<JSONObject>> callBack = new FreeUI_DialogEntityCallBack<BaseResponseBean<JSONObject>>
                            (new TypeToken<BaseResponseBean<JSONObject>>() {
                            }.getType(), getSupportFragmentManager(), this) {

                        @Override
                        public void onSuccess(Response<BaseResponseBean<JSONObject>> response) {
                            super.onSuccess(response);
                            if (response.body().isSuccess(getApplicationContext(), false, getSupportFragmentManager())) {
//                                showConfirmDialog(WaferReceiveActivity.this, "提交成功");
                                if (response.body().isSuccess(getApplicationContext(), false, getSupportFragmentManager())) {
//                                    showConfirmDialog(WaferReceiveActivity.this, "提交成功");
//                                    ShowDialog.showDialog(WaferReceiveActivity.this,"领料成功","MES提示");
                                    showToast("操作成功!",true);
                                    etWoID.setText("");
                                    etWoID.requestFocus();
                                }
                            }
                        }

                        @Override
                        public void onError(Response<BaseResponseBean<JSONObject>> response) {
                            super.onError(response);
                            loadError(response.getException(), "FRAME_TAKE");

                        }
                    };
                    JsonObject map = new JsonObject();
                    map.addProperty("ACTION", "TAKEING");
//                    SimpleDateFormat sbf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String da = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()).toString();
                    map.addProperty("FRAME_SENT_TIME", da);   // PDA的日期存在不准确情况
                    map.addProperty("GET_MAN", Constant.CURRENT_DESC);
                    map.addProperty("WO_ID", getText(etWoID).trim());
                    NetUtils.requestPostNet("IF.FRAME_TAKE", "Common", WaferReceiveActivity.this, map, callBack);
//                });
        }
    }

    @Override
    protected void initData() {

    }
}